package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.ChannelPageDto;
import com.itheima.admin.mapper.AdChannelMapper;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.admin.service.AdChannelService;
import com.itheima.common.vo.PageResultVo;

import org.springframework.stereotype.Service;

import javax.swing.*;
import java.util.List;

@Service
public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService {

    /**
     * 分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageResultVo<AdChannel> pageList(ChannelPageDto dto) {
        //1.设置分页参数
        IPage<AdChannel> pageInfo = new Page<>(dto.getPage(), dto.getSize());

        //2.构建条件对象
        LambdaQueryWrapper<AdChannel> lqw = new LambdaQueryWrapper();
        //2.1 设置分页条件
        lqw.like(StringUtils.isNotEmpty(dto.getName()), AdChannel::getName, dto.getName());
        lqw.eq(dto.getStatus() != null, AdChannel::getStatus, dto.getStatus());

        page(pageInfo, lqw);

        long total = pageInfo.getTotal();
        List<AdChannel> list = pageInfo.getRecords();

        System.out.println("list========================>" + list);

        return PageResultVo.pageResult(pageInfo.getPages(), pageInfo.getSize(), total, list);

    }
}
